class Luhn:
    def __init__(self, card_num):
        self.num = card_num.replace(' ','')
        self.len = len(self.num)
        self.isnum = self.num.isdigit()

    def valid(self):
        if self.len <= 1 or not self.isnum:
            return False
        self.sum = 0
        for i in range(self.len):
            if i % 2 == 0:
                self.sum += int(self.num[-i-1])
            else:
                doubled = int(self.num[-i-1]) * 2
                if doubled >= 9:
                    self.sum += (doubled - 9)
                else:
                    self.sum += doubled
        if self.sum % 10 == 0:
            return True
        return False